package MemberController;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class MemberJoinAjax extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
 
    public MemberJoinAjax() {
        super();
        
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		idCheckProcess(request,response);
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		idCheckProcess(request,response);
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
	}
	
	protected void idCheckProcess(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		
		System.out.println("*****아이디 체크모듈*****");
		
		String resultString ="";
		boolean check = false;
		int result = 0;
		
		MembersBean mbean = new MembersBean();
		MembersDAO mdao = new MembersDAO();
		
		
		
		System.out.println(request.getParameter("Mem_Nick"));
		mbean.setMem_Nick(request.getParameter("Mem_Nick"));
		
		check = mdao.mCheckId(mbean);
			if(check != true){
				System.out.println("*****아이디 중복안됨*****");
				result = 1;
				resultString = "<response><result>"+result+"</result></response>";
				PrintWriter out = response.getWriter();
				response.setContentType("text/xml;charset=utf-8");
				out.println(resultString);
				out.close();
			
			}else
				System.out.println("*****아이디 중복됨*****");
				result = 2;
				resultString = "<response><result>"+result+"</result></response>";
				PrintWriter out = response.getWriter();
				response.setContentType("text/xml;charset=utf-8");
				out.println(resultString);
				out.close();
	}
}
